<template>
	<!-- 定位 -->
	<view>
		<citySelect @back_city="back_city" />
	</view>
</template>

<script>
	import citySelect from '../components/location/location.vue';
	export default {
		data() {
			return {
				region: '',
				backUrl: '',
			};
		},
		components: {
			citySelect
		},
		onLoad(e) {
			console.log("路由传参",e)
			if(e && e.backUrl){
				this.backUrl = e.backUrl;
			}
		},
		methods: {
			back_city(e) {
				console.log("位置信息",e);
				
				if(this.backUrl){
					if(e.deep == 1){
						uni.redirectTo({
							url: this.backUrl+"?city="+e.ext_name
						})
					}
					if(e.deep == 2){
						this.$api.chinaArea_id({},e.pid).then(res=>{
							uni.redirectTo({
								url: this.backUrl+"?city="+res.data.ext_name+"&district="+e.ext_name
							})
						})
					}
					if(e.cityName){
						uni.redirectTo({
							url: this.backUrl+"?city="+e.cityName
						})
					}
				}else{
					if(e.deep == 1){
						getApp().globalData.city = e.ext_name
						getApp().globalData.district = ''
						uni.navigateBack()
					}
					if(e.deep == 2){
						getApp().globalData.district = e.ext_name
						this.$api.chinaArea_id({},e.pid).then(res=>{
							console.log(res,'css');
							getApp().globalData.city = res.data.ext_name
							uni.navigateBack()
						})
					}
					if(e.cityName){
						getApp().globalData.city = e.cityName
						getApp().globalData.district = ''
						uni.navigateBack()
					}
				}
				
					// uni.navigateBack()
				// }else if (e != 'no') {	
				// 	this.region = e.cityName 
				// 	getApp().globalData.city = this.region
				// 	getApp().globalData.district = e.area[index]
				// 	// this.$refs.popupRef.close();
				// 	// uni.navigateBack()
				// } else {
				// 	this.$refs.popupRef.close();
				// }
			}
		}
	}
</script>

<style lang="scss">

</style>
